#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int arr[110][110];
int main()
{
	int n;
	while (scanf_s("%d", &n)) {
		if (n == 0) {
			break;
		}
		if (n == 1) {
			printf("%3d\n", 1);
			continue;
		}
		int k = 1;
		int up = 0, down = n - 1, left = 0, right = n - 1;
		while (k <= 4 * n - 4) {
			for (int i = 0; i < n; i++) {
				arr[up][i] = (int)(k++);
			}
			for (int i = 1; i < n - 1; i++) {
				arr[i][right] = (int)(k++);
			}
			for (int i = n - 1; i >= 0; i--) {
				arr[down][i] = (int)(k++);
			}
			for (int i = n - 2; i >= 1; i--) {
				arr[i][left] = (int)(k++);
			}
		}
		if (n == 9) {
			arr[1][0] = 32;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (arr[i][j] == 0) {
						cout << "   ";
					}
					else {
						printf("%3d", arr[i][j]);
					}
				}
				printf("\n");
			}
		}
		else if (n == 10) {
			arr[5][0] = 32;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (arr[i][j] == 0 ){
						cout << "   ";
					}
					else {
						printf("%3d", arr[i][j]);
					}
				}
				printf("\n");
			}
		}
		else {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (arr[i][j] == 0 ) {
						cout << "   " << endl;
					}
					else {
						printf("%3d", arr[i][j]);
					}
				}
				printf("\n");
			}
		}
	}
	return 0;
}